/**
 * Created by luojie on 2018/3/12.
 * 公用方法。
 */
// const domain = "http://192.168.1.201:8090";//测试
const domain = "http://jsdkapi.hugaint.com:8090";//线上

window.ajax =(url,param = {},type = "get",b = ()=>{})=>{
	return $.ajax({
		url:domain+url,
		dataType:"json",
		beforeSend:b,
		type,
		data:param,

	}).then((data)=>{
		return data;
	})
};
window.setCookie = (key, value, day)=>{
	let exp = new Date();
	exp.setTime(exp.getTime() + day*24*60*60*1000);
	document.cookie = key + "="+ encodeURIComponent (value) + ";expires=" + exp.toGMTString();
};

window.removeCookie = (key)=>{
	setCookie(key, '', -1);//这里只需要把Cookie保质期退回一天便可以删除
};
window.getCookie = (key)=>{
	let cookieArr = document.cookie.split('; ');
	for(let i = 0; i < cookieArr.length; i++) {
		let arr = cookieArr[i].split('=');
		if(arr[0] === key) {
			return decodeURIComponent(arr[1]);
		}
	}
	return "";
};
window.showMsg = (text,position = "center")=>{
	var show  = $('.show_msg').length
	if(show>0){
	}else{
		var div   =  $('<div></div>');
		div.addClass('show_msg');
		var span  = $('<span></span>');
		span.addClass('show_span');
		span.appendTo(div);
		span.text(text);
		$('body').append(div);
	}
	$(".show_span").text(text);
	if(position=='bottom'){
		$(".show_msg").css('bottom','5%');
	}else if(position=='center'){
		$(".show_msg").css('top','');
		$(".show_msg").css('bottom','50%');
	}else{
		$(".show_msg").css('bottom','95%');
	}
	$('.show_msg').hide();
	$('.show_msg').fadeIn(2000);
	$('.show_msg').fadeOut(2000);
	this.timer = setTimeout(()=>{
		$('.show_msg').remove();
		clearTimeout(this.timer)
	},2001)
}
window.getQueryString = ()=> {
	var qs = location.search.substr(1), // 获取url中"?"符后的字串
		args = {}, // 保存参数数据的对象
		items = qs.length ? qs.split("&") : [], // 取得每一个参数项,
		item = null,
		len = items.length;

	for(var i = 0; i < len; i++) {
		item = items[i].split("=");
		var name = decodeURIComponent(item[0]),
			value = decodeURIComponent(item[1]);
		if(name) {
			args[name] = value;
		}
	}
	return args;
}